package com.jxl.controller;


import com.jxl.entity.po.Vehicle;
import com.jxl.entity.query.VehiclePageQuery;
import com.jxl.entity.vo.PageResponse;
import com.jxl.entity.vo.ResponseResult;
import com.jxl.service.IVehicleService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 车辆表 前端控制器
 * </p>
 *
 * @author 金小梁
 * @since 2025-06-08
 */
@Api(tags = "车辆管理")
@RestController
@RequestMapping("/vehicle")
public class VehicleController {
    @Autowired
    private IVehicleService vehicleService;

    @ApiOperation(value = "分页查询车辆信息")
    @PostMapping("/queryVehicles")
    public ResponseResult<PageResponse<Vehicle>> queryVehicles(@RequestBody VehiclePageQuery vehiclePageQuery){
        PageResponse<Vehicle> vehicleVOList = vehicleService.queryVehicles(vehiclePageQuery);
        return ResponseResult.success(vehicleVOList);
    }

    @ApiOperation(value = "新增车辆信息")
    @PostMapping("/addVehicle")
    public ResponseResult<Void> addVehicle(@RequestBody Vehicle vehicle){
        vehicleService.save(vehicle);
        return ResponseResult.success();
    }

    @ApiOperation(value = "删除车辆集合")
    @DeleteMapping("/deleteVehicle")
    public ResponseResult deleteVehicle(@RequestBody List<Integer> vehicleIds){
        vehicleService.deleteByIds(vehicleIds);
        return ResponseResult.success();
    }

    @ApiOperation("查询所有的车辆")
    @GetMapping("/listAllVehicles")
    public ResponseResult listAllVehicles(){
        List<Vehicle> vehicles = vehicleService.list();
        return ResponseResult.success(vehicles);
    }

    @ApiOperation("编辑车辆信息")
    @PostMapping("/editVehicle")
    public ResponseResult editVehicle(@RequestBody Vehicle vehicle){
        boolean result = vehicleService.updateById(vehicle);
        return ResponseResult.success();
    }


}
